package edu.gdkm.dao;

import edu.gdkm.pojo.Template;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TemplateDao {

    // 根据ID查询
    @Select("SELECT * FROM Templates WHERE template_id = #{templateId}")
    Template selectById(Integer templateId);

    // 查询所有模板
    @Select("SELECT * FROM Templates")
    List<Template> selectAll();

    // 根据分类查询模板
    @Select("SELECT * FROM Templates WHERE category = #{category}")
    List<Template> selectByCategory(String category);

    // 查询免费模板
    @Select("SELECT * FROM Templates WHERE is_free = #{isFree}")
    List<Template> selectByIsFree(Boolean isFree);

    // 新增模板
    @Insert("INSERT INTO Templates(name, description, category, preview_image, is_free, created_at, updated_at) " +
            "VALUES(#{name}, #{description}, #{category}, #{previewImage}, #{isFree}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "templateId")
    int insert(Template template);

    // 更新模板
    @Update("UPDATE Templates SET name = #{name}, description = #{description}, category = #{category}, " +
            "preview_image = #{previewImage}, is_free = #{isFree}, updated_at = #{updatedAt} WHERE template_id = #{templateId}")
    int update(Template template);

    // 删除模板
    @Delete("DELETE FROM Templates WHERE template_id = #{templateId}")
    int delete(Integer templateId);
}
    